package com.secondary.action.adminAction;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.secondary.action.BaseAction;
import com.secondary.pojos.Administrator;
import com.secondary.pojos.Goods;
import com.secondary.pojos.User;
import com.secondary.service.AdminService;
import com.secondary.service.GoodsService;
@ParentPackage(value = "AdminAuthority")
@Namespace(value = "/admin")
@Action(value="admin")
@Results({ 
	
	@Result(name = "showSuccess", location = "/admin/adminGoods.jsp"),
	@Result(name = "showUserSuccess", location = "/admin/adminUser.jsp"),
	@Result(name = "showInfoSuccess", location = "/admin/adminCheckGood.jsp"),
	@Result(name = "updateGoodsStateSuccess", location = "/admin/admin!showUncheckedGoods.action" ,type = "redirect"),
		})
public class AdminAction extends BaseAction{
	@Resource
	private AdminService adminService;
	@Resource
	private GoodsService goodsService;
	private List<Goods> uncheckedGoods;
	private List<User> userList;
	private Goods good;

	public String showUncheckedGoodInfo(){
		int id=Integer.parseInt(super.getRequestParameter("id"));
		good=goodsService.findGood(id);
		
		return "showInfoSuccess";
	}
	public String showUncheckedGoods(){
		uncheckedGoods=adminService.findUnCheckedGoods();
		return "showSuccess";
	}
	public String showAllUser(){
		userList=adminService.findAllUser();
		return "showUserSuccess";
	}
	public String updateUserState(){
		int id=Integer.parseInt(super.getRequestParameter("id"));
		int state=Integer.parseInt(super.getRequestParameter("state"));
		adminService.updateUserState(state,id);
		return null;
	}
	public String updateGoodsState(){
		int id=Integer.parseInt(super.getRequestParameter("id"));
		int state=Integer.parseInt(super.getRequestParameter("state"));
		adminService.updateGoodsState(state, id);
		return "updateGoodsStateSuccess";
		
	}
	
	
	public AdminService getAdminService() {
		return adminService;
	}
	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}
	public List<Goods> getUncheckedGoods() {
		return uncheckedGoods;
	}
	public void setUncheckedGoods(List<Goods> uncheckedGoods) {
		this.uncheckedGoods = uncheckedGoods;
	}
	public List<User> getUserList() {
		return userList;
	}
	public void setUserList(List<User> userList) {
		this.userList = userList;
	}
	public GoodsService getGoodsService() {
		return goodsService;
	}
	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	public Goods getGood() {
		return good;
	}
	public void setGood(Goods good) {
		this.good = good;
	}
	
		
	
}
